using DOTS.DOD.LESSON5;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;

namespace DOTS.DOD.LESSON7
{
    readonly partial struct MarchingCubesAspect : IAspect
    {
        readonly RefRW<LocalTransform> mLocalTransform;
        readonly RefRO<MovementSpeed> mMoveSpeed;
        readonly RefRO<RandomTarget> mTargetPos;

        public bool IsNeedDestroy()
        {
            var dis = math.distance(mLocalTransform.ValueRO.Position, mTargetPos.ValueRO.TargetPos);
            return dis <= 0.2f;
        }

        public void Move(float deltaTime)
        {
            float3 dir = math.normalize(mTargetPos.ValueRO.TargetPos - mLocalTransform.ValueRO.Position);
            mLocalTransform.ValueRW.Position += dir * mMoveSpeed.ValueRO.Value * deltaTime;
        }
    }
}